package exam.bak.meituan;

import java.util.Scanner;

public class P4 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String seq = scanner.nextLine().trim();
        int groups = Integer.parseInt(scanner.nextLine().trim());
        while (groups-- > 0) {
            int prefixLen = scanner.nextInt();
            int k = scanner.nextInt();
            System.out.println(solve(seq.substring(0, prefixLen), k));
        }
    }

    public static int solve(String prefix, int k) {
        int len = prefix.length();
        if (len < k) {
            return -1;
        }
        for (int i = 1; i <= len; i++) {//周期长度
            boolean flag = true;
            for (int j = 0; j < len - i; j += i) {
                if (prefix.charAt(j) != prefix.charAt(i + j)) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                if (--k == 0) {
                    return i;
                }
            }
        }
        return -1;
    }
}
